/**
 * 
 */
package com.neal.service.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.neal.domain.Message;
import com.neal.service.IMessageBoardService;


/**
 * @author Neal
 * @version 1.0
 * @description 
 */
@Service(value="messageBoardService")
public class MessageBoardServiceBean implements IMessageBoardService {

	private Map<Long, Message> messages = new LinkedHashMap<Long, Message>();
	
	/* (non-Javadoc)
	 * @see com.neal.service.IMessageBoardService#listMessages()
	 */
	@Override
	public List<Message> listMessages() {
		return new ArrayList<Message>(messages.values());
	}

	/* (non-Javadoc)
	 * @see com.neal.service.IMessageBoardService#postMessage(com.neal.domain.Message)
	 */
	@Override
	public synchronized void postMessage(Message message) {
		message.setId(System.currentTimeMillis());
		messages.put(message.getId(), message);
	}

	/* (non-Javadoc)
	 * @see com.neal.service.IMessageBoardService#deleteMessage(com.neal.domain.Message)
	 */
	@Override
	public synchronized void deleteMessage(Message message) {
		messages.remove(message.getId());
	}

	/* (non-Javadoc)
	 * @see com.neal.service.IMessageBoardService#findMessageById(java.lang.Long)
	 */
	@Override
	public Message findMessageById(Long id) {
		return messages.get(id);
	}

}
